package coffee;

import input.Inputs;

enum State {

    IDLE {
        @Override
        State handle(Inputs input) {
            System.out.println("IDLE state handled");
            if (input == Inputs.BUTTONON) {
                System.out.println("[IDLE] Coffeemachine turned on");
                return READY;
            }
            return IDLE;
        }
    },
    READY {
        @Override
        State handle(Inputs input) {
            System.out.println("READY state handled");
            if (input == Inputs.BUTTONOFF) {
                System.out.println("[READY] Coffeemachine turned off");
                return IDLE;
            }
            if (input == Inputs.BUTTONMILK) {
                System.out.println("[READY] Making frothy milk...");
                return MAKINGMILK;
            }
            if (input == Inputs.BUTTONCOFFEE) {
                System.out.println("[READY] Making coffee...");
                return MAKINGCOFFEE;
            }
            return READY;
        }
    },
    MAKINGMILK {
        @Override
        State handle(Inputs input) {
            System.out.println("MAKINGMILK state handled");
            if (input == Inputs.TIMESTEP) {
                System.out.println("[MAKINGMILK] milk done!");
                return READY;
            }
            return MAKINGMILK;
        }
    },
    MAKINGCOFFEE {
        @Override
        State handle(Inputs input) {
            System.out.println("MAKINGCOFFEE state handled");
            if (input == Inputs.TIMESTEP) {
                System.out.println("[MAKINGCOFFEE] coffee halfway done...");
                return COFFEEHALFWAYDONE;
            }
            return MAKINGCOFFEE;
        }
    },
    COFFEEHALFWAYDONE {
        @Override
        State handle(Inputs input) {
            System.out.println("COFFEEHALFWAYDONE state handled");
            if (input == Inputs.TIMESTEP) {
                System.out.println("[COFFEEHALFWAYDONE] coffee done!");
                return READY;
            }
            return COFFEEHALFWAYDONE;
        }
    };

    abstract State handle(Inputs input);
}
